package com.jwpdk.appframework.controller;

import java.io.IOException;
import java.io.PrintWriter;

import com.jwpdk.util.StringUtils;

public class HandlerAction extends Handler {

	// 空实现
	protected void execute() {
	}

	
	/**
	 * 从request中获取参数，取不到返回""，并且将取到的值trim
	 * @param key
	 * @return
	 */
	protected String getString(String key){
		return StringUtils.trim(getParameter(key,StringUtils.EMPTY));
	}

	/**
	 * 从request中获取参数
	 * @param key	参数名
	 * @param def	取不到时默认值
	 * @return
	 */
	protected String getParameter(String key, String def) {
		return request.getParameter(key) == null ? def : request.getParameter(key);
	}

	/**
	 * 从request中获取参数
	 * @param key	参数名
	 * @return
	 */
	protected String getParameter(String key) {
		return getParameter(key,null);
	}
	
	/**
	 * 用于返回页面AJAX消息
	 * */
	protected void sendAjaxResponse(String msg) {
		try {
			response.setContentType("text/html");
			PrintWriter pw = response.getWriter();
			pw.write(new String(msg.getBytes("UTF-8"), "ISO8859_1"));
		}catch(IOException e) {
			e.printStackTrace();
		}
	}
}
